<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <base th:href="${#request.getContextPath()}+'/'">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!--树组件start-->
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="tree/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="tree/jquery.ztree.core-3.5.js"></script>
    <link type="text/css" rel="stylesheet" href="tree/public.css">
    <!--公用-->
    <link rel="stylesheet" type="text/css" href="tree/ymPrompt.css">
    <script type="text/javascript" src="tree/ymPrompt.js"></script>
    <script type="text/javascript" src="tree/public.js"></script>
    <script type="text/javascript" src="tree/ServerClock.js"></script>
    <script type="text/javascript" src="tree/table.js"></script>
    <script type="text/javascript" src="tree/WdatePicker.js"></script>
    <link href="tree/WdatePicker.css" rel="stylesheet" type="text/css">




</head>
<body style="overflow:auto;background:#FFFFFF;margin:0px;height:100%">

<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
    <tr>
        <td id="frmLefts2" style="border-right: solid 1px #D6E3F3;" width="200">
            <!--            <div style="margin-top: -250px">-->
            <!--树状结构-->
            <div class="zTreeDemoBackgrounds" style="margin-top: -220px">
                <ul id="treeDemo" class="ztree" style="margin-top: -220px">

                </ul>
            </div>
            <!--            </div>-->
        </td>


        <!--商品列表-->
        <td>
            <form name="formSelect" method="post" action="">

                <table style="border-collapse: separate; border-spacing: 6px;" width="100%" cellspacing="6"
                       cellpadding="0" border="0">
                    <tbody>
                    <tr valign="top">

                        <td>
                            <table class="blockTable" width="100%" cellspacing="0" cellpadding="6" border="0">
                                <tbody>
                                <tr>
                                    <td class="blockTd" valign="middle">
                                        <img src="/img/a1.gif">
                                        商品信息列表
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding: 0 8px 4px;">
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false" onclick="add();return false;"><img
                                                src="/img/a2.gif"><b>新增&nbsp;</b>
                                        </a>

                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false"
                                           onclick="toped('toped');return false;"><img
                                                src="/img/a3.gif"><b>置顶&nbsp;</b>
                                        </a>
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false"
                                           onclick="toped('ctoped');return false;"><img
                                                src="/img/a4.gif"><b>取消置顶&nbsp;</b>
                                        </a>
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false"
                                           onclick="recomed('recomed');return false;"><img
                                                src="/img/a5.gif"><b>推荐&nbsp;</b>
                                        </a>
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false"
                                           onclick="recomed('crecomed');return false;"><img
                                                src="/img/a6.gif"><b>取消推荐&nbsp;</b>
                                        </a>
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false"
                                           onclick="upStore(1);return false;"><img
                                                src="/img/a7.gif"><b>上架&nbsp;</b>
                                        </a>
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false"
                                           onclick="upStore(0);return false;"><img
                                                src="/img/a8.gif"><b>下架&nbsp;</b>
                                        </a>
                                        <a href="javascript:void(0);" ztype="zPushBtn" class="zPushBtn" hidefocus="true"
                                           tabindex="-1" onselectstart="return false" onclick="del();return false;"><img
                                                src="/img/a9.gif"><b>删除&nbsp;</b>
                                        </a>
                                        关键词:
                                        <input name="searchText" type="text" id="searchText" onkeydown="enterSubmit();"
                                               class="ipt_style" value="">
                                        <input type="hidden" name="depart_id" id="depart_id" value="">
                                        <input type="button" name="sb" id="sb" class="btn_style" value="查询"
                                               onclick="return search();">
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top: 0px; padding-left: 6px; padding-right: 6px; padding-bottom: 8px;">
                                        <table class="dataTable" sortstring="" id="dg1" page="true" size="0"
                                               multiselect="true" autofill="true" scroll="false" lazy="false"
                                               cachesize="0" width="100%" cellspacing="1" cellpadding="2">
                                            <tbody>
                                            <tr ztype="head" class="dataTableHead">
                                                <td width="5%" align="center">
                                                    序 号
                                                </td>
                                                <td ztype="selector" field="id" width="3%" align="center">
                                                    <input type="checkbox" value="*" id="dg1_AllCheck"
                                                           onclick="DataGrid.onAllCheckClick('dg1')">
                                                </td>
                                                <td width="15%" align="center">
                                                    <b>商品名称</b>
                                                </td>
                                                <td width="15%" align="center">
                                                    <b>商品图片</b>
                                                </td>
                                                <td width="10%" align="center">
                                                    <b>商户名称</b>
                                                </td>
                                                <td width="10%" align="center">
                                                    <b>是否置顶</b>
                                                </td>
                                                <td width="12%" align="center">
                                                    <b>是否推荐</b>
                                                </td>
                                                <td width="15%" align="center">
                                                    <b>价格</b>
                                                </td>
                                                <td width="10%" align="center">
                                                    <b>状态</b>
                                                </td>
                                                <td width="10%" align="center">
                                                    <b>排序</b>
                                                </td>
                                            </tr>

                                            <tr th:each="g,good:${goodList}" id="pb1n3rya_tr" ondblclick="edit('pb1n3rya');"
                                                onclick="DataGrid.onRowClick(this,event);" style="background:#ffffff"
                                                height="35">


                                                <td align="center" th:text="${good.count}">
                                                    1
                                                </td>
                                                <td onclick="DataGrid.onSelectorClick(this,event);"
                                                    ondblclick="stopEvent(event);" align="center">
                                                    <input type="checkbox" name="dg1_RowCheck" id="'dg1_RowCheck'+${good.count}"
                                                           th:value="${g.goodId}">
                                                </td>

                                                <td align="center">
                                                    <a href="#" onclick="edit('pb1n3rya')" th:text="${g.goodName}">444</a>
                                                </td>

                                                <td height="100px" align="center">


                                                    <img src="http://javen666.com:8080/fxmall/imageFolder/20160509/pb1n3rya_1.jpg"
                                                         th:attr="src=${g.goodPic}"
                                                         style="width:150px;height:100px;">

                                                </td>

                                                <td align="center" th:text="${g.customer_name}">
                                                    qq123456
                                                </td>

                                                <td align="center">

                                                    <span class="label label-sm label-danger" th:if="${g.toped==1}">已置顶</span>
                                                    <span class="label label-sm label-danger" th:if="${g.toped==0}">未置顶</span>


                                                </td>

                                                <td align="center">


                                                    <span class="label label-sm label-grey" th:if="${g.recomed==0}">未推荐</span>
                                                    <span class="label label-sm label-grey" th:if="${g.recomed==1}" style="color: red">已推荐</span>

                                                </td>
                                                <td align="center" th:text="${g.skuPrice}">
                                                    1|
                                                </td>

                                                <td align="center" th:if="${g.state==1}" th:id="${g.goodId}">
                                                    <font color="red" >已上架</font>

                                                </td>
                                                <td align="center" th:if="${g.state==0}" th:id="${g.goodId}">

                                                    <font >未上架</font>
                                                </td>


                                                <td align="center" th:text="${g.orderNo}">
                                                    55
                                                </td>
                                            </tr>




                                            <tr>
                                                <td colspan="10" id="dg1_PageBar" class="pagebg" align="center">
                                                    <div style="float: right; font-family: Tahoma;" class="flickr">
                                                        <span th:each="index:${#numbers.sequence(1,size/4 + 1)}">
                                                            <span class="current" th:if="${index==currentPage}" th:text="${currentPage}">1</span>

                                                                <a  th:onclick="'toNextPage('+${index}+')'" th:if="${index!=currentPage}" th:text="${index}"></a>
                                                                    <!--th:href="'goods/list?currentPage='+${index}"--><!--'javascript:toNextPage(\'goods/list?page='+${index-1}+'\')'-->
                                                        </span>


                                                    </div>

                                                    <div style="float: left; font-family: Tahoma">
                                                        共 <span th:text="${size}">2</span> 条记录，每页 4 条，共<span th:text="${size/4 + 1}">2</span> 页
                                                    </div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </td>
    </tr>
    </tbody>
</table>



<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
    $(function () {
        /*加载的时候就请求服务器,获取树结构*/
        $.get("goods/type",function (data) {
            var setting = {
                check: {
                    enable: false
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                }
            };

            var ztree;
            var zNodes = data;
            if(zNodes==null||zNodes==""){
                Exceptalert("查询分类数据出错了哦！",null,false);
            }

            $(document).ready(function(){
                ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                //var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                type = { "Y":"", "N":"s"};
                ztree.setting.check.chkboxType = type;
            });
        });

    });
    function upStore(flag) {
        //flag:1为上架操作,0为下架操作
        /*通过name获取当前选中的checkbox*/
        var goodId = "";
        var checkArray = $("input[name='dg1_RowCheck']");
        for (var i = 0;i<checkArray.length;i++){
            var checked = checkArray[i].checked;
            if (checked) {
                //选中,拼接商品值
                goodId = goodId +$(checkArray[i]).val()+",";
            }
        }
        console.log(goodId);

        var goodIds = goodId.substring(0,goodId.length-1);
        if (goodIds.length <= 0){
            alert("请选择商品!")
            return;
        }
        //post给后台进行上下架操作
        $.post("goods/line",{flag:flag,goodIds:goodIds},function (data) {
            if (data.mark==1){
                alert("成功!");
                var checkArray = $("input[name='dg1_RowCheck']");
                for (var i = 0;i<checkArray.length;i++){
                    var checked = checkArray[i].checked;
                    if (checked) {
                        if (flag == 1){
                            var id = $(checkArray[i]).val();
                            $("#"+id).html("<font color='red' >已上架</font>");
                        } else {
                            var id = $(checkArray[i]).val();
                            $("#"+id).html("<font  >未上架</font>");
                        }
                    }
                }
            }
        });
    }
    function toNextPage(index) {
        $("#right").load("goods/list?currentPage="+index);
    }


</script>
</body>
</html>